﻿using Core.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;

namespace Core.IPepositories
{
    public interface IEntityRepository<T> where T : Entity
    {
        #region 增加数据

        /// <summary>
        /// 添加单条记录
        /// </summary>
        /// <param name="entity">实体对象</param>
        T Insert(T entity);

        /// <summary>
        /// 添加多条记录
        /// </summary>
        /// <param name="entities">实体对象集合</param>
        T InsertOrUpdate(T entity);

        #endregion

        #region 删除数据

        /// <summary>
        /// 删除单条记录
        /// </summary>
        /// <param name="ID">实体主键</param>
        void Delete(Guid ID);

        /// <summary>
        /// 删除单条记录
        /// </summary>
        /// <param name="entity">实体对象</param>
        void Delete(T entity);

        /// <summary>
        /// 删除多条记录
        /// </summary>
        /// <param name="entities">实体对象集合</param>
        void Delete(Expression<Func<T, bool>> where);

        #endregion

        #region 更新数据

        /// <summary>
        /// 更新单条记录
        /// </summary>
        /// <param name="entity">实体对象</param>
        T Update(T entity);

        #endregion

        #region 查询数据

        /// <summary>
        /// 获取所有数据
        /// </summary>
        /// <typeparam name="T">实体泛型</typeparam>
        /// <returns></returns>
        List<T> GetList();

        /// <summary>
        /// 获取指定数据
        /// </summary>
        /// <typeparam name="ID">实体主键</typeparam>
        /// <returns></returns>
        T Get(Guid ID);

        /// <summary>
        /// 分页获取数据
        /// </summary>
        /// <param name="startPage">起始页</param>
        /// <param name="pageSize">页面条目</param>
        /// <param name="rowCount">数据总数</param>
        /// <param name="where">查询条件</param>
        /// <param name="order">排序</param>
        /// <returns></returns>
        IQueryable<T> LoadPageList(int startPage, int pageSize, out int rowCount, Expression<Func<T, bool>> where, Expression<Func<T, object>> order);
        
        #endregion
    }
}
